from ooGame import *

class Player:
	def __init__(self, game, team):
		self.game = game
		self.team = team
		self.methodsDict = {"game": game, "team": team}
		
	def __getitem__(self, item):
		return self.methodsDict[item]
		
class AIPlayer(Player):
	def __init__(self, game, team):
		Player.__init__(self, game, team)
		self.methodsDict['play'] = self.play
		
	def play(self):
		for i in range(Game.boardWidth):
			for j in range(Game.boardHeight):
				if self.game[i,j].upper() == self.game.turn and self.game.turn == self.team:
					self.game.generateMoves((i,j))
					if len(self.game.validMoves) > 0:
						self.game.move((i,j), self.game.validMoves[0])
						return

class HumanPlayer(Player):
	def __init__(self, game, team):
		Player.__init__(self, game, team)
		self.methodsDict['mouseClick'] = self.mouseClick
		
	def mouseClick(self, pieceSelected, pos):
		if self.game[pos[0],pos[1]].upper() == self.game.turn and self.game.turn == self.team:
			self.game.generateMoves(pos)
			return pos
		elif pieceSelected != None and self.game.turn == self.team:
			self.game.move(pieceSelected, pos)
			return None
		else:
			return None
